package cn.nr19.jian.exception


import cn.nr19.jian.token.Token
import java.lang.Exception

/**
 * E3语法报错
 */
open class TokenException(message: String?,pos : Int) : Exception(message) {
    var position : Int = pos
    companion object{
        fun notChar(char: Char,position : Int) = TokenException("无效字符 $char  ${char.code} ; ",position)
        fun inputError(string : String,position: Int) =  TokenException("${string}; }",position)
        fun langError(token: Token) : TokenException{
            return TokenException("语法错误  ${token.type}[${token.text}] ",token.pos) // ${token.type}[${token.text}]
        }
        fun inputError(string : String,token: Token) =  TokenException("${string} ",token.pos)
        fun or(msg : String,position: Int) = TokenException("${msg};",position)
    }
}